package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.system.domain.FxyFinancialSubject;
import com.ruoyi.system.mapper.FxyFinancialVoucherTemplateDetailsMapper;
import com.ruoyi.system.domain.FxyFinancialVoucherTemplateDetails;
import com.ruoyi.system.service.IFxyFinancialVoucherTemplateDetailsService;

/**
 * 凭证模板明细Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-09
 */
@Service
public class FxyFinancialVoucherTemplateDetailsServiceImpl implements IFxyFinancialVoucherTemplateDetailsService 
{
    @Autowired
    private FxyFinancialVoucherTemplateDetailsMapper fxyFinancialVoucherTemplateDetailsMapper;

    /**
     * 查询凭证模板明细
     * 
     * @param id 凭证模板明细主键
     * @return 凭证模板明细
     */
    @Override
    public FxyFinancialVoucherTemplateDetails selectFxyFinancialVoucherTemplateDetailsById(Long id)
    {
        return fxyFinancialVoucherTemplateDetailsMapper.selectFxyFinancialVoucherTemplateDetailsById(id);
    }

    /**
     * 查询凭证模板明细列表
     * 
     * @param fxyFinancialVoucherTemplateDetails 凭证模板明细
     * @return 凭证模板明细
     */
    @Override
    public List<FxyFinancialVoucherTemplateDetails> selectFxyFinancialVoucherTemplateDetailsList(FxyFinancialVoucherTemplateDetails fxyFinancialVoucherTemplateDetails)
    {
        return fxyFinancialVoucherTemplateDetailsMapper.selectFxyFinancialVoucherTemplateDetailsList(fxyFinancialVoucherTemplateDetails);
    }

    /**
     * 新增凭证模板明细
     * 
     * @param fxyFinancialVoucherTemplateDetails 凭证模板明细
     * @return 结果
     */
    @Transactional
    @Override
    public int insertFxyFinancialVoucherTemplateDetails(List<FxyFinancialVoucherTemplateDetails> Details)
    {

        System.out.println(Details);

        return 1;
    }

    /**
     * 修改凭证模板明细
     * 
     * @param fxyFinancialVoucherTemplateDetails 凭证模板明细
     * @return 结果
     */
    @Transactional
    @Override
    public int updateFxyFinancialVoucherTemplateDetails(FxyFinancialVoucherTemplateDetails fxyFinancialVoucherTemplateDetails)
    {
        fxyFinancialVoucherTemplateDetailsMapper.deleteFxyFinancialSubjectById(fxyFinancialVoucherTemplateDetails.getId());
        insertFxyFinancialSubject(fxyFinancialVoucherTemplateDetails);
        return fxyFinancialVoucherTemplateDetailsMapper.updateFxyFinancialVoucherTemplateDetails(fxyFinancialVoucherTemplateDetails);
    }

    /**
     * 批量删除凭证模板明细
     * 
     * @param ids 需要删除的凭证模板明细主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteFxyFinancialVoucherTemplateDetailsByIds(Long[] ids)
    {
        fxyFinancialVoucherTemplateDetailsMapper.deleteFxyFinancialSubjectByIds(ids);
        return fxyFinancialVoucherTemplateDetailsMapper.deleteFxyFinancialVoucherTemplateDetailsByIds(ids);
    }

    /**
     * 删除凭证模板明细信息
     * 
     * @param id 凭证模板明细主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteFxyFinancialVoucherTemplateDetailsById(Long id)
    {
        fxyFinancialVoucherTemplateDetailsMapper.deleteFxyFinancialSubjectById(id);
        return fxyFinancialVoucherTemplateDetailsMapper.deleteFxyFinancialVoucherTemplateDetailsById(id);
    }

    /**
     * 新增科目信息
     * 
     * @param fxyFinancialVoucherTemplateDetails 凭证模板明细对象
     */
    public void insertFxyFinancialSubject(FxyFinancialVoucherTemplateDetails fxyFinancialVoucherTemplateDetails)
    {
        List<FxyFinancialSubject> fxyFinancialSubjectList = fxyFinancialVoucherTemplateDetails.getFxyFinancialSubjectList();
        Long id = fxyFinancialVoucherTemplateDetails.getId();
        if (StringUtils.isNotNull(fxyFinancialSubjectList))
        {
            List<FxyFinancialSubject> list = new ArrayList<FxyFinancialSubject>();
            for (FxyFinancialSubject fxyFinancialSubject : fxyFinancialSubjectList)
            {
                fxyFinancialSubject.setId(id);
                list.add(fxyFinancialSubject);
            }
            if (list.size() > 0)
            {
                fxyFinancialVoucherTemplateDetailsMapper.batchFxyFinancialSubject(list);
            }
        }
    }

    public int examine(Integer[] ids) {
        int examine = fxyFinancialVoucherTemplateDetailsMapper.examine(ids);
        return examine;
    }
}
